package com.ruoyi.hr.common.utils;

import freemarker.template.*;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

/**
 * 模板生成
 */
@Component
public class EmailGenerator {
	@Autowired
	private Configuration cfg;

	public EmailGenerator() throws Exception {
	}

	public String generateEmail(String name, String acceptanceUrl, String declineUrl) throws Exception {
		Template template = cfg.getTemplate("offerAck.ftl");

		Map<String, Object> data = new HashMap<>();
		data.put("name", name);
		data.put("acceptanceUrl", acceptanceUrl);
		data.put("declineUrl", declineUrl);

		Writer out = new StringWriter();
		template.process(data, out);

		return out.toString();
	}
}
